package com.xyl.jms;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xyl.sms.SmsSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

/**
 * 监听消息队列类
 */
@Slf4j
@Component("smsProcessor")
public class SmsProcessor implements MessageListener {

    @Autowired
    @Qualifier("verCodeService")
    private SmsSender smsSender;


    @Override
    public void onMessage(Message message) {

        JSONObject jsonObject = null;
        try {
            jsonObject = JSON.parseObject(((TextMessage)message).getText());
        } catch (JMSException e) {
            log.error("amq SmsProcessor error:",e);
            e.printStackTrace();
        }
        smsSender.sendSms(jsonObject.getString("mobile"),jsonObject.getString("tplId"),jsonObject.getString("vercode"));
    }
}
